﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.OleDb;
using Aandelendelen.Db;

namespace Aandelendelen.Obs
{
	public class UserTotals : BaseDataTable
	{
		public UserTotals(int id)
		{
			QueryArguments args = new QueryArguments();
			args.Add("id", id, OleDbType.Integer);

			Query query = new Query("s_getusertotals", "id", id, OleDbType.Integer);

			ResultSet resultSet = (ResultSet)query.Execute();

			this.Columns.Add(new DataColumn("Description", typeof(string)));
			this.Columns.Add(new DataColumn("Credit", typeof(string)));
			this.Columns.Add(new DataColumn("Debet", typeof(string)));

			this.AddDetails(resultSet);
		}

		private void AddDetails(ResultSet resultSet)
		{
			int numRows = resultSet.Count;

			for (int i = 0; i < numRows; i++)
			{
				int type = (int)resultSet[i, "Type"]; ;

				string amount = "";

				object oAmount = resultSet[i, "Total"];
				amount = ObjectFormatter.GetCurrencyString(oAmount, false);

				DataRow row = this.NewRow();
				row[0] = MutationDescription.GetInstance()[type.ToString()];
				row[1] = (type > 0 ? amount : "");
				row[2] = (type > 0 ? "" : amount);

				this.Rows.Add(row);
			}
		}

	}
}